package com.bluebench.bigul.domain.graphics.simple.polygon;

import java.util.ArrayList;
import java.util.List;

import com.bluebench.bigul.domain.graphics.Graphic;
import com.bluebench.bigul.domain.graphics.Line;
import com.bluebench.bigul.domain.graphics.Point;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.pdf.PdfContentByte;

public class Isosceles extends Triangle{	
	
	public Isosceles(PdfContentByte pdfContent) {
		super(pdfContent);	
	}	

	@Override
	public Polygon build(Point start, List<Float> sides) {
		
		float x = start.getX();
		float y = start.getY();
				
		float base = sides.get(0);
		float side = sides.get(1);
		
		canvas.moveTo(x, y);        
	    canvas.lineTo(x + base, y);
	    canvas.lineTo( (x + (base/2)), (float)(y + Math.sqrt((side*side)+((base*base)/4))   ));
	    
	    vertices.add(new Point(x,y));
	    vertices.add(new Point(x + base, y));
	    vertices.add(new Point((x + (base/2)), (float)(y + Math.sqrt((side*side)+((base*base)/4)))));
	    
	    this.sides.add(new Line(base));
	    this.sides.add(new Line(side));
	    this.sides.add(new Line(side));
	    
	    return this;
		
	}

	@Override
	protected boolean validate() {
		
		Point p1 = getVertices().get(0);		
		Point p2 = getVertices().get(1);		
		Point p3 = getVertices().get(2);
		
		float side1 = new Line(p2,p3).getLength();
		float side2 = new Line(p3,p1).getLength();
		
		if(side1==side2){
			return true;
		}
		
		return false;
		
	}

	@Override
	public Graphic concentric(float distance, boolean in) {
		float x = vertices.get(0).getX();
		float y = vertices.get(0).getY();
		Point start=null;
		float base=0;
		float side=0;
		List<Float> edges = null;
		if(in){
			start = new Point(x+distance,y+distance);
			//TODO : validate that lenght > 2d
			base = sides.get(0).getLength() - (2*distance);
			side = sides.get(1).getLength() - (2*distance);	
			edges = new ArrayList<Float>();
		}else{
			start = new Point(x-distance,y-distance);
			//TODO : validate that lenght > 2d
			base = sides.get(0).getLength() + (2*distance);
			side = sides.get(1).getLength() + (2*distance);
			edges = new ArrayList<Float>();
		}
		edges.add(base);
		edges.add(side);
		return build(start,edges);	
		
	}

	@Override
	public Graphic copy(float distance, int direction) {
		// TODO Auto-generated method stub
		return null;
	}

	

	
}
